import { getAreaObj, regularRule } from '@/utils/util'

export const formConfig = {
	inline: false,
	showBtn: true,
	labelPosition: 'top',
	column: [
		{
			label: '个人照片',
			prop: 'avatar',
			type: 'upload',
			listType: 'picture-card',
			labelPosition: 'top',
			showFileList: false,
			limit: 1,
			changeField: true,
			span: 24,
		},

		{
			label: '姓名',
			prop: 'adviserName',
			type: 'text',
			span: 12,
			rules: [{ required: true, message: '请输入姓名' }],
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'text',
			span: 12,
			change: (item, form) => {
				if (form.idCard) form.idCard = form.idCard.toUpperCase()
			},
			rules: [
				{ pattern: regularRule.idCard, message: '请输入正确的证件号码' },
				{ required: true, message: '请输入身份证号' },
			],
		},
		{
			label: '联系方式',
			prop: 'adviserPhone',
			type: 'text',
			span: 12,
			rules: [
				{ pattern: regularRule.phone, message: '请输入正确的联系方式' },
				{ required: true, message: '请输入联系方式' },
			],
		},
		{
			label: '专家类型',
			prop: 'adviserType',
			propName: 'adviserTypeLabel',
			type: 'remoteSelect',
			code: 'ADVISER_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 12,
			rules: [{ required: true, message: '请选择专家类型' }],
		},
		{
			label: '现居地区',
			prop: 'areas',
			propName: 'areasName',
			type: 'AplidAreaSelect',
			span: 12,
			rules: [{ required: true, message: '请输入现居地区' }],
		},
		{
			label: '现居地址',
			prop: 'address',
			type: 'textarea',
			autosize: {
				minRows: 1,
			},
			span: 12,
			rules: [{ required: true, message: '请输入现居地址' }],
		},
		{
			label: '擅长领域',
			prop: 'skilledField',
			type: 'textarea',
			autosize: {
				minRows: 1,
			},
			span: 24,
		},
		{
			label: '顾问履历介绍',
			prop: 'adviserIntroduce',
			type: 'textarea',
			span: 24,
		},
		{
			label: '相关证书信息',
			type: 'dynamicForm',
			prop: 'adviserCertificate',
			span: 24,
			tabType: 'form',
			custome: 'table',
			config: {
				inline: false,
				showBtn: false,
				labelPosition: 'top',
				maxHeight: '30rem',
				addBtn: true,
				delBtn: true,
			},
			stripe: true,
			border: true,
			column: [
				{
					label: '证书名称',
					prop: 'certificateName',
					type: 'text',
					span: 12,
				},
				{
					label: '证书编号',
					prop: 'certificateNumber',
					type: 'text',
					span: 12,
				},
				{
					label: '证书附件信息',
					uploadTip: '证书照片',
					prop: 'certificatePhoto',
          listType:'picture-card',
					type: 'upload',
					labelPosition: 'top',
					custome: 'file',
					showFileList: true,
					limit: 6,
					multiple: true,
					changeField: true,
					span: 24,
				},
			],
		},
	],
}

export const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '姓名',
			prop: 'adviserName',
			type: 'input',
			span: 8,
		},
		{
			label: '身份证号',
			prop: 'idCard',
			type: 'input',
			span: 8,
		},

		{
			label: '联系方式',
			prop: 'adviserPhone',
			type: 'input',
			span: 8,
		},
		{
			label: '专家类型',
			prop: 'adviserType',
			propName: 'adviserTypeLabel',
			type: 'remoteSelect',
			code: 'ADVISER_TYPE',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '状态',
			prop: 'onlineFlag',
			type: 'select',
			dicData: [
				{ label: '离线', value: 0 },
				{ label: '在线', value: 1 },
			],
			span: 8,
		},
	],
}

export const tableConfig = {
	stripe: true,
	border: true,
	columns: [
		{ label: '所属区域', prop: 'beAreaNames' },
		{ label: '姓名', prop: 'adviserName' },
		{ label: '身份证号', prop: 'idCard' },
		{ label: '联系方式', prop: 'adviserPhone' },
		{ label: '年龄', prop: 'age' },
		{ label: '性别', prop: 'genderLabel' },
		{ label: '专家类型', prop: 'adviserTypeLabel' },
		{
			label: '状态',
			prop: 'onlineFlag',
			custome: 'tag',
			dicData: [
				{ label: '离线', value: 0, type: 'danger' },
				{ label: '在线', value: 1, type: 'success' },
			],
		},
		{
			label: '操作',
			prop: 'menu',
			width: 300,
			fixed: 'right',
		},
	],
}

export const api = {
	index: 'view_amAdviser_page',
	add: 'view_amAdviser_add',
	edit: 'view_amAdviser_edit',
	delete: 'view_amAdviser_del',
	detail: 'view_amAdviser_view',
	export: 'view_amAdviser_export',
}
export const auth = {
	...api,
}
export const baseConfig = {
	pageName: '银发顾问专家',
	dictcodes: ['ADVISER_TYPE'],
	rowKey: 'id',
	addLabel: '新增',
	tipLabel: 'adviserName',
	exportMqTopic: '/ning/export/',
	api,
	auth,
	menuBtn: [
		{
			icon: 'editor',
			label: '编辑',
			type: 'primary',
			operate: 'edit',
			auth: auth.edit,
			text: true,
			show: true,
		},
		{
			icon: 'delete',
			label: '删除',
			type: 'danger',
			operate: 'delete',
			auth: auth.delete,
			text: true,
			show: true,
		},
		{
			icon: 'detail',
			label: '详情',
			type: 'primary',
			operate: 'detail',
			auth: auth.index,
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(form.areas, '')
			const areasNameObj: any = getAreaObj(form.areasName, '')
			if (form.adviserCertificate && !Array.isArray(form.adviserCertificate)) {
				form.adviserCertificate = JSON.parse(form.adviserCertificate)
			}
			resolve({
				...form,
				...areasObj,
				...areasNameObj,
				areas: undefined,
			})
		})
	},
	operateFormate: async (form, type) => {
		return new Promise((resolve, reject) => {
			const areaObj: any = getAreaObj(form, '', 'get')
			resolve({
				...form,
				...areaObj,
				areas: areaObj.areaIds,
				areasName: areaObj.names,
			})
		})
	},
	beforeOnLoadFormate: async (query) => {
		return new Promise((resolve, reject) => {
			const areasObj: any = getAreaObj(query.areas, 'be')
			resolve({
				...query,
				...areasObj,
				areas: undefined,
			})
		})
	},
	dialogConfig: {
		width: '75%',
	},
	searchConfig,
	formConfig,
	tableConfig,
	detailConfig: formConfig,
}
